package io.github.novaframe.config;

import io.github.novaframe.web.error.ErrorCode;

/**
 * 全局错误
 * @author Locki
 * @date Mar 21, 2017 5:55:13 PM
 * @version 1.0
 *
 */
public enum NovaframeCode implements ErrorCode {
	
	SYSTEM_BUSY(-1, "system busy"), // 系统繁忙，此时请开发者稍候再试
	SUCCESS(0, "success"), // 请求成功

	// 1000+ 通用异常
	INVALID_PARAMTER(1001, "invalid parameter"), // 错误的参数
    CONCURRENCY_FAILURE(1002, "concurrency failure"), // 数据并发异常
    ACCESS_DENIED(1003, "access denied"), // 访问拒绝
    VALIDATION_FAILURE(1004, "validation failure"), // 数据校验失败
    METHOD_NOT_SUPPORTED(1005, "method not supported"), // http方法不支持
    INTERNAL_SERVER_ERROR(1006, "internal server error"), // 系统内部异常
    INVALID_ACCESSTOKEN(1007,"Invalid AccessToken"), // TOKEN无效
    INVALID_SIGNATURE(1008,"Invalid Signature"), // 签名无效

    // 1100+ 集成组件异常
    QUARTZ_ERROR(1101, "quartz error") // quartz模块异常
	;
	
	private Integer errcode;
	private String errmsg;

    NovaframeCode(Integer errcode, String errmsg) {
		this.errcode = errcode;
		this.errmsg = errmsg;
	}

	@Override
	public Integer value() {
		return errcode;
	}

    @Override
	public String desc() {
		return errmsg;
	}

	public static NovaframeCode valueOf(Integer errcode ) {
        if (errcode == null) {
            return null;
        }

        for (NovaframeCode novaframeCode : values()) {
            if (novaframeCode.value().equals(errcode) ) {
                return novaframeCode;
            }
        }
        return null;
    }
}
